def palSubstr(s):
    """

    find longest palindromic substring of s
    :type s: str
    :rtype: str
    """
    totalLen = len(s);
    if totalLen <= 1:
        return s;

    maxLen = 0;
    index = 0;
    cursor = 0;

    listD = ['#'] * (2 * totalLen + 1);
    listD.append('$');

    for i in range(0, 2 * totalLen + 1):
        if i % 2 != 0:
            listD[i] = s[i // 2];

    print(listD);
    p = [0] * (2 * totalLen + 1);
    for i in range(1, 2 * totalLen + 1):
        if p[cursor] + cursor > i:
            p[i] = min(p[2 * cursor - i], p[cursor] - (i - cursor));
        else:
            p[i] = 1;
        while listD[i - p[i]] == listD[i + p[i]]:
            p[i] += 1;
            if i - p[i] < 0 or i + p[i] > 2 * totalLen + 1:
                break;
        print(p[i]);
        if cursor + p[cursor] < i + p[i]:
            cursor = i;
            print('cursor', cursor);
        if maxLen < p[i]:
            maxLen = p[i];
            index = i;
            print('index', index);

    print('Max length', maxLen - 1);
    return s[(index - maxLen + 1) // 2 : (index - maxLen + 1) // 2 + maxLen - 1];        
